package service

import (
	"ruoyi-hello/app/sys/model"
	"slices"
)

func GetRolePermission(user model.SysUser) ([]string, []int) {
	if user.IsAdmin() {
		roles := make([]string, 0) // 创建一个长度为5的int类型的slice
		roles = append(roles, "admin")
		return roles, nil
	} else {
		return selectRolePermissionByUserId(user.UserId)

	}
}

func GetMenuPermission(user model.SysUser, roles []int) []string {
	perms := make([]string, 0) // 创建一个长度为5的int类型的slice
	if user.IsAdmin() {
		perms = append(perms, "*:*:*")
		return perms
	}
	if roles != nil && len(roles) > 0 {
		for _, role := range roles {
			rolePerms := SelectMenuPermsByRoleId(role)
			for _, perm := range rolePerms {
				if !slices.Contains(perms, perm) {
					perms = append(perms, perm)
				}
			}
		}
		return perms
	}
	return nil
}
